import express from 'express'
import config from './config.js'
import nunjucks from 'nunjucks'
import indexRouter from './routers/index'
import advertRouter from './routers/advert'
import errLog from './middlewares/err_log'
import bodyParser from './middlewares/body-parser'
const app = express()
//挂在静态资源
app.use('/public',express.static(config.public_path))
app.use('/node_modules',express.static(config.node_modules_path))
//nunjucks模板配置
nunjucks.configure('views', {
  autoescape: true,
  express: app,
  noCache: true
});

// 挂载解析表单 POST 请求体中间件
app.use(bodyParser)
//挂载路由
app.use(indexRouter)
app.use(advertRouter)

//挂在全局错误处理中间件
app.use(errLog)
app.listen(3010,() => {
  console.log('服务已启动。。。,在浏览器中输入http://localhost:3010/即可访问')
})